package jp.co.cos.ittrick.channel.controller.client;

import jp.co.cos.ittrick.channel.meta.PreModelMeta;
import jp.co.cos.ittrick.channel.model.PreModel;
import jp.co.cos.ittrick.channel.service.PreService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class GetPreController extends Controller {

    private PreService preService;

    public GetPreController() {
        preService = new PreService();
    }

    @Override
    protected Navigation run() throws Exception {

        // リクエストパラメータ
        String chapter = asString("pre");

        PreModel preModel = preService.getPreByKey(Integer.valueOf(chapter));

        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json");
        response.getWriter().println(PreModelMeta.get().modelToJson(preModel));
        response.flushBuffer();

        return null;
    }

}
